package com.generator.utils;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @version 1.0
 * @Author Xing
 * @Date 2023/4/28 8:19
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel("Result响应")
public class Result implements Serializable {
    @ApiModelProperty(value="编码 200：成功 其他值代表失败")
    private Integer code;
    @ApiModelProperty(value="消息内容")
    private Object data;
    @ApiModelProperty(value="响应数据")
    private String msg;

    public Result ok(Object data){
        Result result = new Result();
        result.setCode(200);
        result.setData(data);
        result.setMsg("SUCCESS");
        return result;
    }

    public Result ok(){
        Result result = new Result();
        result.setCode(200);
        result.setMsg("SUCCESS");
        return result;
    }

    public Result err(Integer code, String msg){
        Result result = new Result();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }

    public Result err(Integer code){
        Result result = new Result();
        result.setCode(code);
        result.setMsg("ERROR");
        return result;
    }
}

